
.LC0:
	.string "%s\n"

.globl main

main:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movl $234,%edi
	call dec2octal 

	movq %rax,%rsi
	leaq .LC0(%rip),%rdi
	movl $0,%eax 
	call printf 

	movl $0,%eax
	leave
	ret


dec2octal:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movl %edi,-0x1000(%rbp) /* num */
	movq $0,-0xff0(%rbp) /* p */
	movl $0,-0xfe0(%rbp) /* i */
	movq $0,-0xfd0(%rbp) /* dst */
	movl $0,-0xfc0(%rbp) /* len */
	movq $0,-0xfb0(%rbp) /* str */

	movl $100,%edi
	call malloc 
	movq %rax,-0xff0(%rbp) /* p */
	
.Ldec2bina_500:
	movl -0x1000(%rbp),%eax
	movl $2,%ebx
	xorq %rdx,%rdx
	idivl %ebx
	movl %eax,%ecx
	movl %eax,-0x1000(%rbp) 

	movl -0xfe0(%rbp),%eax /* i */
	sall $2,%eax
	movslq %eax,%rax
	movq -0xff0(%rbp),%rdi 
	movl %edx,0(%rdi,%rax,1) /* p[i] */

	addl $1,-0xfe0(%rbp) /* i */

	cmpl $0,%ecx
	jne .Ldec2bina_500

	movl -0xfe0(%rbp),%eax /* i */
	movl %eax,-0xfc0(%rbp) /* len */

	
	movl -0xfe0(%rbp),%eax
	sall $2,%eax
	movl %eax,%edi
	call malloc 
	movq %rax,-0xfd0(%rbp) /* dst */

.Ldec2bina_300:
	movl -0xfe0(%rbp),%eax /* i */
	subl $1,%eax 
	sall $2,%eax
	movslq %eax,%rax
	movq -0xff0(%rbp),%rdi 
	movl 0(%rdi,%rax,1),%ecx
	
	movl -0xfe0(%rbp),%eax /* i */
	movl -0xfc0(%rbp),%ebx /* len */ 
	subl %eax,%ebx 
	movl %ebx,%eax 
	sall $2,%eax
	movslq %eax,%rax
	movq -0xfd0(%rbp),%rdi 
	movl %ecx,0(%rdi,%rax,1)

	subl $1,-0xfe0(%rbp) /* i */
	
	cmpl $0,-0xfe0(%rbp)
	jne .Ldec2bina_300

	movl $100,%edi 
	call malloc 
	movq %rax,-0xfb0(%rbp) /* str */

.Ldec2bina_200:
	movl -0xfe0(%rbp),%eax /* i */
	sall $2,%eax
	movslq %eax,%rax
 	movq -0xfd0(%rbp),%rdi /* dst */
 	movl 0(%rdi,%rax,1),%eax /* dst[i] */
	addb $48,%al
	movb %al,%cl

	movl -0xfe0(%rbp),%eax /* i */
	movslq %eax,%rax
	movq -0xfb0(%rbp),%rdi /* str */
	movb %cl,0(%rdi,%rax,1) /* str[i] */

	addl $1,-0xfe0(%rbp) /* i */
	
	movl -0xfe0(%rbp),%eax /* i */
	cmpl -0xfc0(%rbp),%eax /* len */
	jne .Ldec2bina_200 

	movl -0xfe0(%rbp),%eax /* i */
	movslq %eax,%rax
	movq -0xfb0(%rbp),%rdi /* str */
	movb $0,0(%rdi,%rax,1) /* str[i] */

	movq -0xfb0(%rbp),%rax /* str */
	leave
	ret

